#include "AEWorker.hpp"
#include "AETask.hpp"
#include "AETaskManager.hpp"

#include <mutex>

BEGIN_ARETE_NAMESPACE(thread)

	void AEWorker::operator()()
{
	while(true)
	{
		std::unique_lock<std::mutex> lock(m_pool.m_mutex);

		while(!m_pool.m_stop && m_pool.m_tasks.empty())
			m_pool.m_condition.wait(lock);

		if(m_pool.m_stop)
			return;

		AETask task(m_pool.m_tasks.front());
		m_pool.m_tasks.pop_front();
		lock.unlock();

		task();
	}
}

END_ARETE_NAMESPACE